import { Platform, StatusBar } from 'react-native';
import ExtraDimensions from 'react-native-extra-dimensions-android';

/**
 * 获取状态栏高度
 * 优先使用 ExtraDimensions，如果失败则回退到 StatusBar.currentHeight
 */
export const getStatusBarHeight = (): number => {
    if (Platform.OS === 'android') {
        try {
            // 尝试使用 ExtraDimensions 获取状态栏高度
            const extraDimensionsHeight = ExtraDimensions.getStatusBarHeight();
            if (extraDimensionsHeight && extraDimensionsHeight > 0) {
                return extraDimensionsHeight;
            }
        } catch (error) {
            console.warn('ExtraDimensions.getStatusBarHeight() failed:', error);
        }

        // 回退到 StatusBar.currentHeight
        return StatusBar.currentHeight || 0;
    }

    return 0;
};

/**
 * 获取安全区域顶部高度（状态栏高度）
 */
export const getSafeAreaTopHeight = (): number => {
    return getStatusBarHeight();
}; 